/**
 * Created by liubin on 2015/9/16.
 */
'use strict';

const Autobind = {
    componentWillMount() {
        // 因为调用mixin的话，有一层包装
        // 遍历到最外层
        let me = this;
        while (me && !me.isPrototypeOf(Object)) {
            if(me.hasOwnProperty('render')){
                break;
            } else {
                me = Object.getPrototypeOf(me);
            }
        }
        Object.getOwnPropertyNames(me).filter( value => {
            if (typeof this[value] === 'function') {
                return true;
            }
        }).forEach( value => {
            this[value] = this[value].bind(this);
        });
    }
}

export default Autobind;